<div class="container-fluid">
    <div class="block-header">
        <h2>功能管理 > 电影 > 添加新电影</h2>
    </div>
    <!-- Vertical Layout -->
    <div class="row">
        <div class="col-lg-6 col-md-6">
            <div class="card">
                <div class="header">
                    <h2>添加新电影</h2>
                </div>
                <div class="body">
                    <div class="" id="film-alert"></div>
                    <form class="newforum" method="POST" id="new-film">
                    	 <div class="form-group form-float">
                            <div class="form-line">
                                <input type="text" id="embed_source" name="iframe" class="form-control" onchange="Wo_ToggleMoviewsSource(this)">
                                <label class="form-label">电影视频直链 <small>比如: (site.com/video.mp4)</small></label>
                            </div>
                        </div>
                        <div class="preview-utube-import hidden" style="margin-top: 25px;">
							<iframe width="100%" height="350px" src="" frameborder="0" allowfullscreen></iframe>
						</div>
                         <div class="form-group form-float">
                            <div class="form-line"> 或者上传电影 <br><br>
                                <input type="file" name="source" id="film" accept="video/*" value="C:\fakepath\source">
                            </div>
                        </div>
                        <br>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <input type="text" id="name" name="name" class="form-control">
                                <label class="form-label">电影标题</label>
                            </div>
                        </div>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <textarea name="description" id="description" class="form-control" cols="30" rows="3"></textarea>
                                <label class="form-label">描述</label>
                            </div>
                        </div>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <textarea name="stars" id="stars" class="form-control" cols="30" rows="3"></textarea>
                                <label class="form-label">星级 <small>用逗号分开,</small></label>
                            </div>
                        </div>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <input type="text" id="producer" name="producer" class="form-control">
                                <label class="form-label">制片人</label>
                            </div>
                        </div>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <input type="number" id="release" name="release" class="form-control" min="1960" max="<?php echo date('Y') ?>">
                                <label class="form-label">发行方</label>
                            </div>
                        </div>
                         <div class="form-group form-float">
                            <div class="form-line">
                                <input type="number" id="duration" name="duration" class="form-control" min="10" max="350">
                                <label class="form-label">时间长度</label>
                            </div>
                        </div>
                        <br>
                        <label for="country">国家</label>
                        <select class="form-control show-tick" id="country" name="country">
                        <?php foreach ($wo['countries'] as $c_key => $c_value): ?>
							<option value="<?php echo $c_key; ?>"><?php echo $c_value; ?></option>
						<?php endforeach; ?>
                        </select>
                        <div class="clearfix"></div>
                        <br><br>
                        <label for="quanlity">视频质量</label>
                        <select class="form-control show-tick" id="quanlity" name="quanlity">
			                <option value="cam">CAMRip</option>
							<option value="ts">TS</option>
							<option value="vsh">VHSRip</option>
							<option value="wp">WP</option>
							<option value="scr">SCR (VHSScr)</option>
							<option value="dvds">DVDScr</option>
							<option value="ts">TC</option>
							<option value="ldr">LDRip</option>
							<option value="tv">TVRip</option>
							<option value="sat">SATRip</option>
							<option value="dvb">DVBRip</option>
							<option value="dtv">DTVRip</option>
							<option value="dvd">DVD</option>
							<option value="hdr">HDRip</option>
							<option value="web-dl">WEB-DL</option>
							<option value="hd-tv">HD-TV</option>
							<option value="hd">HD DVD</option>
                        </select>
                        <div class="clearfix"></div>
                        <br><br>
                        <label for="genre">类型</label>
                        <select class="form-control show-tick" id="genre" name="genre">
                        <?php foreach ($wo['film-genres'] as $g_key => $g_value): ?>
							<option value="<?php echo $g_key; ?>"><?php echo $g_value; ?></option>
						<?php endforeach;?>
                        </select>
                        <div class="clearfix"></div>
                        <br><br>
                        <label for="new-blog-desc" title="上传" class="pointer">封面</label>  
				        <div class="main pointer" id="select-f-cover">
				           <label class="pointer"><i class="fa fa-camera fa-wh" aria-hidden="true"></i> <?php echo $wo['lang']['select'] ?></label>
				        </div>
				         <div id="progress" style="display: none">
				            <span id="percent">0%</span>
				            <div class="progress">
				             <div id="bar" class="progress-bar progress-bar-striped active"></div> 
				            </div>
				            <div class="clear"></div>
				         </div>
				      <input type="file" class="hidden" name="cover" id="film-cover" accept="image/*">
                        <input type="hidden" name="hash_id" value="<?php echo Wo_CreateSession();?>">
                        <button type="submit" id="upload-film" class="btn btn-primary m-t-15 waves-effect">添加电影</button>
                    </form>
                </div>
            </div>
        </div>
        <div class="clearfix"></div>
    </div>
    <!-- #END# Vertical Layout -->
<script>

	jQuery(document).ready(function($) {
		var bar = $('#bar');
	    var percent = $('#percent');
	    var status = $('#status');
	    var publisher_button = $('#publisher-button');
		$("#select-f-cover").click(function(event) {
	      $("#film-cover").click()
	    });

	    $("#film-cover").change(function(event) {
	      $("#select-f-cover").html("<img src='" + window.URL.createObjectURL(this.files[0]) + "' alt='Picture'  class='w100'>")
	    });


	    $('#new-film').ajaxForm({
	      url: Wo_Ajax_Requests_File() + '?f=new-film',
	      beforeSend: function() {
	      	var percentVal = '0%';
	        bar.width(percentVal);
	        percent.html(percentVal);
	      },
	      uploadProgress: function (event, position, total, percentComplete) {
           var percentVal = percentComplete + '%';
           bar.width(percentVal);
           $('#progress').slideDown(200);
           if(percentComplete > 50) {
             percent.addClass('white');
           }
           percent.html(percentVal);
         },
	      type:"POST",
	      success: function(data) {
	      	$("html, body").animate({ scrollTop: 0 }, "slow");
	        bar.width(0);
	        percent.html('0%');
	        $('#progress').slideUp(200);
	        if (data['status'] == 200) {
	          $("#film-alert").html('<div class="alert alert-success">'+ data['message'] +'</div>');
	          $('#new-film').resetForm();
	        } 
	        else if (data['message']) {
	          $("#film-alert").html('<div class="alert alert-danger">' + data['message'] + '</div>');
	        } 
	      }});
	    $(".delete-film").click(function(event) {
	    	$("#delete-film").attr('data-film-ident', $(this).attr('id')).modal('show');
	    });
	});

	function Wo_IsURL(str) {
	  var pattern = new RegExp('^(https?:\\/\\/)?'+ 
	  '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.?)+[a-z]{2,}|'+ 
	  '((\\d{1,3}\\.){3}\\d{1,3}))'+ 
	  '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ 
	  '(\\?[;&a-z\\d%_.~+=-]*)?'+ 
	  '(\\#[-a-z\\d_]*)?$','i'); 
	  return pattern.test(str);
	}

	function Wo_FilmMediaUrl(pastedData) {
		var success = false;
		var media   = {};
		if (GetYoutubeId(pastedData)) {

		    media.type  = "youtube";
		    media.id    = GetYoutubeId(pastedData);
		    success     = true;
		    $("#embed_source").attr('name', 'iframe');
		}

		else if (Wo_GetVimeoID(pastedData)) {
		    media.type  = "vimeo";
		    media.id    = Wo_GetVimeoID(pastedData);
		    success     = true;
		    $("#embed_source").attr('name', 'iframe');
		}

		else if (Wo_IsURL(pastedData)) {
		    media.type  = "other";
		    media.id    = pastedData;
		    success     = true;
		    $("#embed_source").attr('name', 'other');
		}

		if (success) { 
			return media; 
		}

		else { 
			alert("Not valid source id detected"); 
			return false;
		}
	}

	function  Wo_ToggleMoviewsSource(self = false) {
		if (!self || self.value.length == '') {
			$('#film').attr('disabled', false);
			return false;
		}
		$('#film').attr('disabled', true);
		var url_data = Wo_FilmMediaUrl(self.value);
		if (url_data && url_data.type == 'youtube') {
			var u_source = "https://www.youtube.com/embed/" + url_data.id;
			$(".preview-utube-import").removeClass('hidden').find('iframe').attr('src', u_source);
			self.value = u_source;
		}
		else if (url_data && url_data.type == 'vimeo') {
			var u_source = "https://player.vimeo.com/video/" + url_data.id;
			alert(u_source)
			$(".preview-utube-import").removeClass('hidden').find('iframe').attr('src', u_source);
			self.value   = u_source;
		}
		else if (url_data && url_data.type == 'other') {
			var u_source = url_data.id;
			var html = "\
			<div class='video-js-responsive-container vjs-hd'>\
			<video onplay='' class='video-js vjs-big-play-centered' controls preload='auto' poster='' data-setup='{}'>\
			    <source src='"+u_source+"' type='video/mp4'>\
			    <source src='"+u_source+"' type='video/webm'>\
			</video>\
			<script src='<?php echo $wo['config']['theme_url'];?>/player/Video/video.js'><\/script>\
			</div>\ ";
			$(".preview-utube-import").removeClass('hidden').html(html);
			self.value = u_source;
		}
	}


	function Wo_GetVimeoID(str) {

		if (str.indexOf('#') > -1) {
			str = str.split('#')[0];
		}

		if (str.indexOf('?') > -1) {
			str = str.split('?')[0];
		}

		var id;

		if (/https?:\/\/vimeo\.com\/[0-9]+$|https?:\/\/player\.vimeo\.com\/video\/[0-9]+$/igm.test(str)) {
			var arr = str.split('/');
			if (arr && arr.length) {
				id = arr.pop();
			}
		}
		return id;
	}




	function GetYoutubeId(str) {
		var shortcode = /youtube:\/\/|https?:\/\/youtu\.be\//g;

		if (shortcode.test(str)) {
			var shortcodeid = str.split(shortcode)[1];
			return Wo_StripParameters(shortcodeid);
		}
		var inlinev = /\/v\/|\/vi\//g;

		if (inlinev.test(str)) {
			var inlineid = str.split(inlinev)[1];
			return Wo_StripParameters(inlineid);
		}
		var parameterv = /v=|vi=/g;

		if (parameterv.test(str)) {
			var arr = str.split(parameterv);
			return arr[1].split('&')[0];
		}

		var embedreg = /\/embed\//g;

		if (embedreg.test(str)) {
			var embedid = str.split(embedreg)[1];
			return Wo_StripParameters(embedid);
		}

		var userreg = /\/user\//g;

		if (userreg.test(str)) {
			var elements = str.split('/');
			return Wo_StripParameters(elements.pop());
		}

		var attrreg = /\/attribution_link\?.*v%3D([^%&]*)(%26|&|$)/;

		if (attrreg.test(str)) {
			return str.match(attrreg)[1];
		}
	}
	 


	function Wo_StripParameters(str) {
		if (str.indexOf('?') > -1) {
			return str.split('?')[0];
		}

		return str;
	}
</script>